var database = require('../../data/data.js');
Page({
  data: {
    finish1: false,
    finish2: false,
    flag: true,
  },
  onLoad: function (options) {

  },
  submit: function (e) {
    var that = this;
    wx.request({
      url: database.url + '/api/V2/user/binding_wechat_small',
      method: "POST",
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        username: e.detail.value.tel,
        password: e.detail.value.password,
        accessToken: database.accessToken,
        unionid: database.unionid,
        smscode: "smscode"
      },
      success(res) {
        if (res.data.status_reason != "登录绑定小程序成功！") {
          that.setData({
            flag: false,
            registered_status_text: res.data.status_reason
          })
        } else {
          database.id = res.data.data.userId;
          database.login = true;
          wx.navigateTo({
            url: "/pages/home/home"
          })
        }
      }
    })
  },
  tel: function (e) {
    if (e.detail.value.length == 11) {
      this.setData({
        finish1: true,
        tel: e.detail.value
      })
    } else {
      this.setData({
        finish1: false
      })
    }
  },
  psd: function (e) {
    if (e.detail.value.length != "") {
      this.setData({
        finish2: true,
        psd: e.detail.value
      })
    } else {
      this.setData({
        finish2: false
      })
    }
  },
  know: function (e) {
    this.setData({
      flag: true
    })
  }
})